import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class VideoTypeMenuView extends StatelessWidget {
  final List<String> titleArr;
  final int selectIndex;
  final Function(int)? callback;
  final AlignmentGeometry? alignment;

  const VideoTypeMenuView(
    this.titleArr, {
    Key? key,
    this.selectIndex = 0,
    this.callback,
    this.alignment,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    List<Widget> widgetArr = [];
    for (int i = 0; i < titleArr.length; i++) {
      widgetArr.add(_buildMenuButton(titleArr[i], i == selectIndex, i));
    }
    return Container(
      alignment: alignment ?? Alignment.centerLeft,
      child: Row(
        mainAxisSize: MainAxisSize.min,
        children: widgetArr,
      ),
    );
  }

  Widget _buildMenuButton(String text, bool isSelected, int index) {
    bool isLast = index == (titleArr.length - 1);
    return InkWell(
      onTap: () {
        callback?.call(index);
      },
      child: Container(
        padding: EdgeInsets.fromLTRB(0, 12, 0, 12),
        child: Row(
          mainAxisSize: MainAxisSize.min,
          children: [
            // const SizedBox(width: 4),
            Text(
              text,
              style: TextStyle(
                fontSize: 16.sp,
                color: isSelected ? Color(0xE5FFFFFF) : Color(0x73FFFFFF),
              ),
            ),
            if (!isLast)
              Padding(
                padding: EdgeInsets.symmetric(horizontal: 12.w),
                child: Text(
                  "|",
                  style: TextStyle(
                    fontSize: 12.sp,
                    color: Colors.white.withOpacity(0.05),
                  ),
                ),
              ),
          ],
        ),
      ),
    );
  }
}
